﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NCAB.WF
{
    public partial class Home_Profile : System.Web.UI.Page
    {
        private MembershipUser user;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            }

            if (Request.IsAuthenticated && Membership.GetUser() != null)
            {
                user = Membership.GetUser();

                string WSUser = ConfigurationManager.AppSettings["WSUser"];
                string WSPass = ConfigurationManager.AppSettings["WSPass"];
                imgProfileDetail.Src = "img/profiles/" + user.UserName + ".jpg";
                ScriptManager.RegisterStartupScript(this, GetType(), "scriptGetUsuario", "GetUsuario_ByUserName('" + user.UserName + "', '" + WSUser + "', '" + WSPass + "');", true);
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }

        void Page_PreRender(object obj, EventArgs e)
        {
            ViewState["update"] = Session["update"];
        }

        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            try
            {
                services.WS_User ws = new services.WS_User();
                aspnet_UserExtraInfo userextra = new aspnet_UserExtraInfo();
                userextra.NombreUsuario = Membership.GetUser().UserName;
                userextra.Nombres = txtNombres.Text;
                userextra.Apellidos = txtApellidos.Text;
                userextra.Identificacion = txtIdentificacion.Text;
                userextra.TMovil = txtMovil.Text;
                userextra.TOficina = txtOficina.Text;
                userextra.Direccion = txtDireccion.Text;
                userextra.AboutMe = txtAboutMe.Text;

                if (ws.UpdateUser(userextra, ConfigurationManager.AppSettings["WSUser"], ConfigurationManager.AppSettings["WSPass"]))
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "scriptUpdateUser", "mensaje_exito();", true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}